package com.spring.sunflower.common;


import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by Kevin on 2021/7/16<br/>
 * <p>
 * Describe:<br/>
 */
public class RelationAdapter extends FragmentPagerAdapter {
    private List<String> mTitleList;
    private List<Fragment> mFragments;

    public RelationAdapter(@NonNull @NotNull FragmentManager fm, List<String> mTitleList, List<Fragment> mFragments) {
        super(fm);
        this.mTitleList = mTitleList;
        this.mFragments = mFragments;
    }

    public RelationAdapter(@NonNull @NotNull FragmentManager fm, int behavior, List<String> mTitleList, List<Fragment> mFragments) {
        super(fm, behavior);
        this.mTitleList = mTitleList;
        this.mFragments = mFragments;
    }

    public void updateData(List<String> title, List<Fragment> fragment) {
        mTitleList.clear();
        mFragments.clear();
        mTitleList.addAll(title);
        mFragments.addAll(fragment);
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mTitleList == null ? 0 : mTitleList.size();
    }


    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        return mTitleList.get(position);
    }

    @NonNull
    @NotNull
    @Override
    public Fragment getItem(int position) {
        return mFragments.get(position);
    }
}
